/*
 * @Author: dingyuwen ding_yuwen@163.com
 * @Date: 2023-02-16 10:34:02
 * @LastEditTime: 2023-04-10 18:17:22
 * @LastEditors: DingYuwen 43669762+DingYuwen@users.noreply.github.com
 * @Description:
 */
import {
  BoxProps,
  FormControl,
  FormLabel,
  Popover,
  PopoverArrow,
  PopoverContent,
  PopoverProps,
  PopoverTrigger,
} from '@chakra-ui/react';
import { ReactNode } from 'react';

type IAIPopoverProps = PopoverProps & {
  label: string;
  triggerComponent: ReactNode;
  triggerContainerProps?: BoxProps;
  children: ReactNode;
  styleClass?: string;
  hasArrow?: boolean;
};

const IAIPopover = (props: IAIPopoverProps) => {
  const { label, triggerComponent, children, hasArrow = true, ...rest } = props;

  return (
    <FormControl>
      {label && (
        <FormLabel fontSize="sm" fontWeight="bold" marginRight={0}>
          {label}
        </FormLabel>
      )}
      <Popover {...rest}>
        <PopoverTrigger>{triggerComponent}</PopoverTrigger>
        <PopoverContent>
          {hasArrow && <PopoverArrow />}
          {children}
        </PopoverContent>
      </Popover>
    </FormControl>
  );
};

export default IAIPopover;
